/*
* coder: dzlua
* email: 505544956@qq.com
* time : 2018/05/14 10:28
*/
#ifndef __UTILS_HPP__
#define __UTILS_HPP__
#pragma once

#include <string>
#include <sstream>
#include <fstream>
#include <iostream>

typedef std::string string;
typedef std::wstring wstring;
#if defined(UNICODE) || defined(_UNICODE)
    typedef std::wstring tstring;
#else
    typedef std::string tstring;
#endif

namespace {

// for format.
template <typename T, typename D>
auto _format(T& ss, const D& d) {
    ss << d;
}
    
}

/*
* format string
*/
template <typename... Args>
string format(Args&&... args) {
    std::stringstream ss;
    std::initializer_list<int>{ (
        _format(ss, std::forward<Args>(args))
        , 0 )...};
    return ss.str();
}
template <typename... Args>
wstring wformat(Args&&... args) {
    std::wstringstream ss;
    std::initializer_list<int>{ (
        _format(ss, std::forward<Args>(args))
        , 0 )...};
    return ss.str();
}
template <typename... Args>
tstring tformat(Args&&... args) {
    #if defined(_UNICODE) || defined(UNICODE)
        return wformat(args...);
    #else
        return format(args...);
    #endif
}

void show(const string& d) {
    std::cout << d << std::endl;
}
void wshow(const wstring& d) {
    std::wcout << d << std::endl;
}
void tshow(const tstring& d) {
    #if defined(_UNICODE) || defined(UNICODE)
        wshow(d);
    #else
        show(d);
    #endif
}

void log(const string& d) {
    std::ofstream f;
    f.open("icon-clear.log", std::ios::app);
    f << d << std::endl;
    f.close();
}
void wlog(const wstring& d) {
    std::wofstream f;
    f.open("icon-clear.log", std::ios::app);
    f << d << std::endl;
    f.close();
}
void tlog(const tstring& d) {
    #if defined(_UNICODE) || defined(UNICODE)
        wlog(d);
    #else
        log(d);
    #endif
}

#endif